package com.heyqing.topic.DeleteDuplicates_0083;

import java.util.Objects;

/**
 * ClassName:DeleteDuplicates
 * Package:com.heyqing.topic.DeleteDuplicates_0083
 * Description:
 *
 * @Date:2024/9/11
 * @Author:Heyqing
 */
public class DeleteDuplicates {
    public ListNode deleteDuplicates(ListNode head) {
        if (Objects.isNull(head)){
            return null;
        }
        ListNode prefix = head;
        ListNode res = prefix;
        ListNode p = head;
        p = p.next;
        while (!Objects.isNull(p)){
            if (p.val == prefix.val){
                prefix.next = p.next;
                p = p.next;
            }else {
                prefix = p;
                p =p.next;
            }
        }
        return res;
    }
}
